package com.sunda.spmsorder.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunda.spmsorder.entity.ShoppingScenarioDtl;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 请购场景表明细 Mapper 接口
 * </p>
 *
 * @author Wayne
 * @since 2021-03-01
 */
@Mapper
@Component
public interface ShoppingScenarioDtlMapper extends BaseMapper<ShoppingScenarioDtl> {

    @Select("\n" +
            "SELECT SSD.UUID AS \"uuid\",\n" +
            "       SS.SCENARIO_ID AS \"scenarioId\",\n" +
            "       SSD.SSD_ROW_ID AS \"ssdRowId\",\n" +
            "       SSD.MATERIAL_NO AS \"materialNo\",\n" +
            "       SSD.QUANTITY AS \"quantity\",\n" +
            "       SSD.LONG_CONTRACT_CODE AS \"longContractCode\",\n" +
            "       SSD.BRAND AS \"brand\",\n" +
            "       SAP.MATERIAL_ZH_DESC AS \"materialZhDesc\",\n" +
            "       SAP.MATERIAL_EN_DESC AS \"materialEnDesc\",\n" +
            "       SAP.SUPPLY_DESC AS \"supplyDesc\",\n" +
            "       SAP.BASIC_UNIT AS \"basicUnit\",\n" +
            "       SRM.SUPPLIER_CODE AS \"supplierCode\",\n" +
            "       SRM.SUPPLIER_NAME AS \"supplierName\",\n" +
            "       SRM.PROCUREMENT_ORGANIZATION AS \"procurementOrganization\",\n" +
            "       SRM.MIN_ORDER_QUANTITY AS \"minOrderQuantity\",\n" +
            "       SRM.MIN_PACK_QUANTITY AS \"minPackQuantity\",\n" +
            "       SRM.SOURCE_GOODS AS \"sourceGoods\"\n" +
            "FROM SHOPPING_SCENARIO_DTL SSD\n" +
            "    LEFT JOIN SHOPPING_SCENARIO SS ON SSD.UUID = SS.UUID\n" +
            "    LEFT JOIN MATERIAL_SAP SAP ON SSD.MATERIAL_NO = SAP.MATERIAL_NO\n" +
            "    LEFT JOIN MATERIAL_SRM_LONG_CONTRACT SRM ON SSD.LONG_CONTRACT_CODE = SRM.LONG_CONTRACT_CODE\n" +
            "WHERE SSD.UUID = #{uuid}\n")
    List<Map<String, Object>> getScenarioDtlList(@Param("uuid") String uuid);
}
